﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class cms_cmsGallerys : System.Web.UI.Page
{
    private const string ImageGallery = "gallery-img.jpg";
    private const string ImageGallery2 = "gallery-img2.jpg";
    private const string ImageGallery3 = "gallery-img3.jpg";
    private const string ImageGallery4 = "gallery-img4.jpg";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadImageDesign();
        }
    }

    private void LoadImageDesign()
    {
        if (File.Exists(Server.MapPath("~/images/" + ImageGallery)))
        {
            imgGallery1.ImageUrl = "~/images/" + ImageGallery;
            System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/images/" + ImageGallery));
            lblSizeGallery1.Text = "(H x W:" + img.Height + " x " + img.Width + " )";
        }
        if (File.Exists(Server.MapPath("~/images/" + ImageGallery2)))
        {
            imgGallery2.ImageUrl = "~/images/" + ImageGallery2;
            System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/images/" + ImageGallery2));
            lblSizeGallery2.Text = "(H x W:" + img.Height + " x " + img.Width + " )";
        }
        if (File.Exists(Server.MapPath("~/images/" + ImageGallery3)))
        {
            imgGallery3.ImageUrl = "~/images/" + ImageGallery3;
            System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/images/" + ImageGallery3));
            lblSizeGallery3.Text = "(H x W:" + img.Height + " x " + img.Width + " )";
        }
        if (File.Exists(Server.MapPath("~/images/" + ImageGallery4)))
        {
            imgGallery4.ImageUrl = "~/images/" + ImageGallery4;
            System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/images/" + ImageGallery4));
            lblSizeGallery4.Text = "(H x W:" + img.Height + " x " + img.Width + " )";
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (FileUploadGallery1.HasFile && Utils.IsImageFile(FileUploadGallery1.FileName))
        {
            FileUploadGallery1.SaveAs(Server.MapPath("~/images/" + ImageGallery));
        }
        if (FileUploadGallery2.HasFile && Utils.IsImageFile(FileUploadGallery2.FileName))
        {
            FileUploadGallery2.SaveAs(Server.MapPath("~/images/" + ImageGallery2));
        }
        if (FileUploadGallery4.HasFile && Utils.IsImageFile(FileUploadGallery4.FileName))
        {
            FileUploadGallery4.SaveAs(Server.MapPath("~/images/" + ImageGallery4));
        }
        if (FileUploadGallery3.HasFile && Utils.IsImageFile(FileUploadGallery3.FileName))
        {
            FileUploadGallery3.SaveAs(Server.MapPath("~/images/" + ImageGallery3));
        }
    }
}